/**
 * 初始化爬虫管理详情对话框
 */
var CrawlerMgrEditDlg = {
    data: {
        source: "",
        logoUrl: "",
        sourceUrl: "",
        status: ""
    }
};

/**
 * 关闭此对话框
 */
CrawlerMgrEditDlg.close = function () {
    parent.layer.close(window.parent.CrawlerMgr.layerIndex);
};

/**
 * 验证表单
 */
CrawlerMgrEditDlg.validateForm = function () {

    var data = CrawlerMgrEditDlg.data;

    if (!data.source) {
        return "来源不能为空";
    }
    if (!data.status) {
        return "状态不能为空";
    }
    if (!data.sourceUrl) {
        return "网站地址不能为空";
    }
    return true;
};

/**
 * 提交修改
 */
CrawlerMgrEditDlg.addSubmit = function() {

    var ajax = new $ax(Feng.ctxPath + "/crawlerMgr/update", function(data){
        parent.Feng.success("修改成功!");
        window.parent.CrawlerMgr.table.refresh();
        CrawlerMgrEditDlg.close();
    },function(data){
        parent.Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.data);
    ajax.start();
}

$(function() {

    //初始化定时任务的详情数据
    var ajax = new $ax(Feng.ctxPath + "/crawlerMgr/detail/" + Feng.getUrlParam("id"));
    var result = ajax.start();
    CrawlerMgrEditDlg.data = result.data;

    CrawlerMgrEditDlg.app = new Vue({
        el: '#crawlerMgrForm',
        data: CrawlerMgrEditDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = CrawlerMgrEditDlg.validateForm();
                if (result === true) {
                    CrawlerMgrEditDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                CrawlerMgrEditDlg.close();
            }
        }
    });
});
